package logic

import (
	"context"
	"github.com/jjl309/oneGroup"
	"math/rand"
	"time"
	user "user_srv/proto"
)

func (u *UserServer) Send(ctx context.Context, req *user.SendSmsRequest) (*user.SendSmsResponse, error) {
	key := "code:" + req.Tel + ":"
	code := rand.Intn(9000) + 1000
	/*sms, err := oneGroup.Sms(req.Tel, strconv.Itoa(code))
	if err != nil {
		return nil, err
	}
	if *sms.Body.Code != "OK" {
		return nil, errors.New(*sms.Body.Message)
	}*/
	err := oneGroup.Rdb.Set(context.Background(), key, code, 5*time.Minute).Err()
	if err != nil {
		return nil, err
	}
	return &user.SendSmsResponse{Success: true}, nil
}
